// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.Collections;
// import java.util.List;

#include "MySqlKillStatement.h"
#include "../../../../ast/SQLExpr.h"
#include "../../../../ast/SQLObject.h"
#include "../../../../ast/SQLStatementImpl.h"
#include "../../../../visitor/SQLASTVisitor.h"
#include "../../../../../utils/listTran.h"

MySqlKillStatement_Type_ptr MySqlKillStatement_Type::CONNECTION = MySqlKillStatement_Type_ptr(new MySqlKillStatement_Type(1 << 0, make_string_ptr("CONNECTION")));
MySqlKillStatement_Type_ptr MySqlKillStatement_Type::QUERY = MySqlKillStatement_Type_ptr(new MySqlKillStatement_Type(1 << 1, make_string_ptr("QUERY")));

MySqlKillStatement_Type::MySqlKillStatement_Type(uint64_t mask, string_ptr name)
{
  this->mask = mask;
  this->name = name;
}

MySqlKillStatement::MySqlKillStatement()
{
  threadIds = std::make_shared<std::list<SQLExpr_ptr>>();
}

MySqlKillStatement_Type_ptr MySqlKillStatement::getType()
{
  return type;
}

void MySqlKillStatement::setType(MySqlKillStatement_Type_ptr type)
{
  this->type = type;
}

SQLExpr_ptr MySqlKillStatement::getThreadId()
{
  auto it_threadIds = threadIds->begin();
  return *it_threadIds;
}

void MySqlKillStatement::setThreadId(SQLExpr_ptr threadId)
{
  if (this->threadIds->empty())
  {
    this->threadIds->push_back(threadId);
    return;
  }
  auto it_threadIds = threadIds->begin();
  std::advance(it_threadIds, 0);
  *it_threadIds = threadId;
}

SQLExpr_list_ptr MySqlKillStatement::getThreadIds()
{
  return threadIds;
}

void MySqlKillStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(MySqlKillStatement)))
  {
    SQLObject_list_ptr tmp = ListTran::tran_class<SQLExpr, SQLObject>(threadIds);
    acceptChild(visitor, tmp);
  }
  visitor->endVisit(SharedObject(MySqlKillStatement));
}

// @Override
SQLObject_list_ptr MySqlKillStatement::getChildren()
{
  SQLObject_list_ptr tmp = std::make_shared<std::list<SQLObject_ptr>>();
  return tmp;
}
